/*
 * 查房列表
 * @author 醉雪
 * @time 2018/10/17
 * @since 1.0.0
 * */
// React基础组件
import React from 'react'
// dva 连接组件 - 连接route和model
import { connect } from 'dva'
// 引入antd的组件
import {Form, Select, Input, DatePicker, Button, Popconfirm, Modal} from 'antd'
import moment from 'moment';
const { RangePicker } = DatePicker;
const dateFormat = 'YYYY/MM/DD';
//导入路由组件，用于跳转等
import { Link, hashHistory } from 'dva/router'
// 导入项目全局配置文件
import config from 'config/config'

// 引入model取值工具方法
import { mapStateToProps } from 'utils/view_utils'
// 当前组件样式
import styles from './questionnaireStyle.less'

import Cookie from 'js-cookie'



import cx from 'classnames'



const Option = Select.Option;
/**
 * description 路由视图及事件处理
 * dispatch 分发到models中的effects对应事件名
 * model 用于获取models中state定义的数据
 * form 表单对象
 */

const questionnaireView = function ({ dispatch, model, form }) {
    const { modelObj, namespace } = model
    let { token, height } = modelObj
    
    let xheight = document.body.clientHeight - 60 - 47 - 60 - 44
    
    function calculateHeight (height){
        dispatch({
            type: `${namespace}/updateStore`,
            payload: { height:height }
        });
    }

    let xtoken = Cookie.get(config.cookie.auth)
    let targetURL = config.qvpHost + 'project/my?token='+xtoken
    dispatch({
        type: `${namespace}/updateStore`,
        payload: { token:xtoken }
    });
    console.log("---------------------",xtoken)
    

    return (
        <div className={cx('pageLayout')}>
            <iframe 
                style={{width:'100%', height:`${xheight}px`, overflow:'visible'}}
                onLoad={() => {
                    const obj = ReactDOM.findDOMNode(this);
                    console.log(obj,"-------------")
                    calculateHeight(obj.contentWindow.document.body.scrollHeight)
                }} 
                ref="iframe" 
                src={targetURL} 
                width="100%" 
                height={xheight} 
                scrolling="no" 
                frameBorder="0"
            />
        </div>

    )
}

// 连接视图(view)和模型(model)
export default connect(mapStateToProps)(Form.create()(questionnaireView))
